<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<div class="bjui-pageHeader">
	<!--form表单注意点--
		1.表单增加opertion属性（属性对应的value可以如下），没有加这个属性，默认用EqualTo
			"IsNull", // XXXX is null
            "IsNotNull", // XXXX is not null
            "EqualTo", // 等于 =
            "NotEqualTo", // 不等于 <>
            "GreaterThan", // 大于 >
            "GreaterThanOrEqualTo", // 大于等于 >=
            "LessThan", // 小于 <
            "LessThanOrEqualTo", // 小于等于 <=
            "Like", // 模糊查询 XXXX like %value%
            "NotLike", // XXXX not like %value%
            "LeftLike", // XXXX like %value
            "NotLeftLike", // XXXX not like %value
            "RightLike", // XXXX like value%
            "NotRightLike", // XXXX not like value%
            "In", // in ()
            "NotIn", // not in ()
            "Between", // 范围 between
            "NotBetween"// not between
	 -->
	<form id="pagerForm" method="post" action="$!{webPath}/tssy/tsSyUserRole/queryPageForLookup" onsubmit="return pkgParam(this);" data-toggle="ajaxsearch" >
    	<!-- 分页参数 -->
    	<input type="hidden" name="pageSize" value="$!{resultPage.limit}">
    	<input type="hidden" name="pageCurrent" value="$!{resultPage.page}">
		<!-- 基本查询框 -->
        <div class="bjui-searchBar">
				<label for="j-roleName" class="control-label x85">&nbsp;角色名称：</label>
				<input type="hidden" name="userId" value="$!{record.userId}"/>
				<input type="text" name="roleName" id="j-roleName" value="$!{record.roleName}" size="15" class="form-control"/>&nbsp;
				<label>&nbsp;已有角色：</label> <input type="radio" class="form-control" #if($!record.isHave&&$record.isHave=='1')checked#end
				name="isHave" id="j-enable" value="1" /><label for="j-enable">&nbsp;是</label>
				<input type="radio" class="form-control" #if($!record.isHave&&$record.isHave=='0')checked#end
				name="isHave" id="j-disable" value="0" /><label for="j-disable">&nbsp;否</label>
            <button type="submit" class="btn-default" data-icon="search">查询</button>&nbsp;
            <a class="btn btn-orange" href="javascript:;" data-toggle="reloadsearch" data-clear-query="true" data-icon="undo">清空查询</a>
        </div>
	</form>
</div>
<div class="bjui-pageContent tableContent">
    <table class="table table-bordered table-hover table-striped table-top" data-selected-multi="true">
        <thead>
            <tr>
					<th data-order-field="roleName">角色名称</th>
					<th data-order-field="remark">角色描述</th>
                <th width="120">操作</th>
            </tr>
        </thead>
        <tbody>
            #foreach($obj in ${resultPage.resultList})
            <tr data-id="$!{obj.id}">
					<td>$!obj.roleName</td>
					<td>$!obj.remark</td>
               <td>
               #if($!obj.userId)
					<a href="javascript:void(0)" data-icon="check" onclick="delRelation('$!obj.id','$!obj.userId',this)"
					class="btn btn-red" data-toggle="lookupback">取消</a>
			   #elseif(!$!obj.userId)
			   	<a href="javascript:void(0)" data-icon="check" onclick="addRelation('$!obj.id',this)"
					class="btn btn-blue" data-toggle="lookupback">选择</a>
			   #end
			  </td>
            </tr>
			#end
        </tbody>
    </table>
</div>
<!-- 列表分页信息 -->
#parse("WEB-INF/page/common/pageBar.html")
<script type="text/javascript">
	var fa = "<i class='fa fa-check'></i>";
	function delRelation(roleId,userId,obj){
		 $.ajax({
	         url: '$!{webPath}/tssy/tsSyUserRole/saveUserRole',
	         type: 'post',
	         data: {"flag":"0","userId":userId,"roleId":roleId},
	         dataType: 'json',
	         async:false,
	         success: function(d){
	        	 $(obj).attr("onclick","addRelation('"+roleId+"',this)");
	        	 $(obj).html(fa+" 选择");
	        	 $(obj).attr("class","btn btn-blue");
	         }
	     });
	}
	
	function addRelation(roleId,obj){
		 var userId = "$!userId";
		 $.ajax({
	         url: '$!{webPath}/tssy/tsSyUserRole/saveUserRole',
	         type: 'post',
	         data: {"flag":"1","userId":userId,"roleId":roleId},
	         dataType: 'json',
	         async:false,
	         success: function(d){
	        	 $(obj).attr("onclick","delRelation('"+roleId+"',"+"'"+userId+"',this)");
	        	 $(obj).html(fa+" 取消");
	        	 $(obj).attr("class","btn btn-red");
	         }
	     });
	}
</script>
